﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VideoReflector.Models;

namespace VideoReflector.Video
{
    /// <summary>
    /// Implementation of IClipStreamer which uses libvlc to export video clips to a file on disk
    /// </summary>
    public class VlcClipExporter : VlcClipStreamer
    {
        #region Private fields

        private string _outputPath; 

        #endregion // Private fields

        #region Constructor

        /// <summary>
        /// Constructor for VlcClipExporter object
        /// </summary>
        /// <param name="clipTags"> Collection of ClipTag objects which correspond to the clips to be exported </param>
        /// <param name="sessionVideo"> Object containing details of video file associated with session </param>
        /// <param name="sessionFileDirectory"> Directory where session files are contained in on disk </param>
        /// <param name="outputPath"> Path to save generated video clips file to </param>
        public VlcClipExporter(IList<ClipTag> clipTags, VideoFileType sessionVideo, string sessionFileDirectory, string outputPath)
            : base(clipTags, sessionVideo, sessionFileDirectory)
        {
            _outputPath = outputPath;
            base.Initialise();
        }

        #endregion // Constructor

        #region Overrides

        protected override string[] GenerateMediaItemOptions(ClipTag tag)
        {
            var options = new List<string>(base.GenerateMediaItemOptions(tag));
            string mux = Path.GetExtension(_outputPath).Substring(1);
            options.Add(String.Format(":sout=#std{{access=file{{append}},mux={0},dst={1}}}", mux, _outputPath));
            //options.Add(":sout-keep");
            return options.ToArray();
        }

        #endregion // Overrides
    }
}
